package jvm.gc;


public class FinalizeTest {


    public static  FinalizeTest finalizeTest = new FinalizeTest();

    @Override
    protected void finalize() throws Throwable {
        System.out.println("垃圾回收开始调用finalize方法。。。。");
        if (finalizeTest==null){
            System.out.println("调用finalize 开始复活......");
            super.finalize();
            finalizeTest = new FinalizeTest();
        }
        if (finalizeTest!=null){
            System.out.println("调用finalize 复活成功......");
        }else {
            System.out.println("调用finalize 复活失败......");
        }

    }

    public static void main(String[] args) throws InterruptedException {

        FinalizeTest finalizeTest = new FinalizeTest();
        finalizeTest.finalizeTest = null;
        System.gc();
        Thread.sleep(4000);
//        finalizeTest.finalizeTest = null;
//        System.gc();
//        Thread.sleep(4000);
//        finalizeTest.finalizeTest = null;
//        System.gc();
//        Thread.sleep(4000);


    }

    public int  str(int i){
        return i;
    }
}
